/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nominalitzacions.ui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Dani.camacho.rodriguez
 */
public class RemoveVerbDicView extends JFrame {
        
        private VerbDictionaryViewController VDVC;
        
        private JPanel mainPanel = new JPanel();
        private JLabel inf = new JLabel("Verb :");
        private JTextField verb = new JTextField();
        private JButton remove = new JButton("Rm.");
        
        public RemoveVerbDicView(VerbDictionaryViewController VDVC){
            this.VDVC = VDVC;
            iniComponents();
        }
        
    private void iniComponents() {
        iniFrame();
        iniMainPanel();
        assignListeners();
    }
    
    private void iniFrame(){
        setMinimumSize(new Dimension(250, 75));
        this.setLocationRelativeTo(null);
        this.setPreferredSize(this.getMinimumSize());
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setTitle("Remove Verb of Dictionary");
        setResizable(false);
        JPanel contentPane = (JPanel) this.getContentPane();
        contentPane.add(mainPanel);
    }
    
    private void iniMainPanel(){

        GroupLayout layout = new GroupLayout(mainPanel);
        mainPanel.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        GroupLayout.SequentialGroup heightGroup = layout.createSequentialGroup();
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(inf));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(verb));
        heightGroup.addGroup(layout.createParallelGroup()
            .addComponent(remove));
        layout.setHorizontalGroup(heightGroup);

        GroupLayout.SequentialGroup verGroup = layout.createSequentialGroup();
        verGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE)
                .addComponent(inf)
                .addComponent(verb)
                .addComponent(remove));
        layout.setVerticalGroup(verGroup);
                verb.setPreferredSize(new Dimension(25,10));
    }
    
    private void assignListeners(){
        remove.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evento){
                try {
                    removeVerb();
                } catch (IOException ex) {
                    String msg = ex.getMessage();
                    JOptionPane.showMessageDialog(new JPanel(), msg, "Error writing",
                                                    JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    }
    
    private void removeVerb() throws IOException{
        VDVC.remove(verb.getText());
    }
    
}
